package com.example.content.fragment.me.vip

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.viewpager.widget.PagerAdapter
import com.example.content.R
import kotlinx.android.synthetic.main.vip_center_card_layout.view.*

/**
 * Created by zhudongao
 * Desc
 * Date 2/28/21
 */
class VipCardPagerAdapter(private val views: List<View>) : PagerAdapter() {
    override fun getCount() = views.size

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val view = views[position]
        val bg = view.findViewById<View>(R.id.vip_center_card)
        val currentLevel = view.findViewById<ImageView>(R.id.current_level)
        val levelRes:Int
        val bgRes = when (position) {
            0 -> {
                levelRes = R.drawable.vip_current_level
                R.drawable.vip_degree_bg_v1
            }
            1 -> {
                levelRes = R.drawable.vip_no_level
                R.drawable.vip_degree_bg_v2
            }
            2 -> {
                levelRes = R.drawable.vip_no_level
                R.drawable.vip_degree_bg_v3
            }
            3 -> {
                levelRes = R.drawable.vip_no_level
                R.drawable.vip_degree_bg_v4
            }
            4 -> {
                levelRes = R.drawable.vip_no_level
                R.drawable.vip_degree_bg_v5
            }
            5 -> {
                levelRes = R.drawable.vip_no_level
                R.drawable.vip_degree_bg_v6
            }
            6 -> {
                levelRes = R.drawable.vip_no_level
                R.drawable.vip_degree_bg_v7
            }
            else -> {
                levelRes = R.drawable.vip_no_level
                R.drawable.vip_degree_bg_v1
            }
        }
        bg.setBackgroundResource(bgRes)
        currentLevel.setImageResource(levelRes)
        container.addView(view)
        return view
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(views[position])
    }

}